package com.apes.fn.ssm.model;

import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.scm.masterdata.enumeration.model.Enumeration;
import com.apes.scm.masterdata.product.model.Product;
import com.apes.scm.masterdata.stock.model.Location;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;

@Getter
@Setter
@DynamicUpdate
@DynamicInsert
@SelectBeforeUpdate
@Table(name = StockCalcuResult.CONST_TABLE_NAME)
@EntityListeners(DefaultPersistListener.class)
@Entity
public class StockCalcuResult extends BaseModel {
    public static final String CONST_TABLE_NAME = "stock_calcu_result";

    @Id
    @Column(name = "id", length = 10)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "测算结果")
    @Comment("编码")
    private String id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "location_id", referencedColumnName = "id")
    @Comment(value = "仓库")
    private Location location;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "product_id", referencedColumnName = "id")
    @Comment(value = "商品")
    private Product product;


    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "fitting_message_id", referencedColumnName = "id")
    @Comment(value = "组合配件")
    private FittingMessage fittingMessage;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "brand_priority_id", referencedColumnName = "id")
    @Comment(value = "品牌优先级")
    private Enumeration brandPriority;

    @Column(name = "brand_priority_serial_number", columnDefinition = "number(5) default 0")
    @Comment(value = "品牌优先级序号")
    private int brandPrioritySerialNumber = 0; // BRAND_PRIORITY_XH

    @Column(name = "count_model", columnDefinition = "number(5) default 0")
    @Comment(value = "车型计数")
    private int countModel = 0; // COUNT_CX

    @Column(name = "model_serial_number", columnDefinition = "number(5) default 0")
    @Comment(value = "车型排序")
    private int modelSerialNumber = 0; // COUNT_CX_PW

    @Column(name = "active_members_number", columnDefinition = "number(19) default 0")
    @Comment(value = "有效会员数量")
    private int activeMembersNumber = 0;

    @Column(name = "match_sales", columnDefinition = "number(5) default 0")
    @Comment(value = "匹配销量")
    private int matchSales = 0;

    @Column(name = "actual_sales", columnDefinition = "number(5) default 0")
    @Comment(value = "实际销量")
    private int actualSales = 0;

    @Column(name = "dis_all_sum_vip_end", columnDefinition = "number(19) default 0")
    @Comment(value = "去重 VIP 总和最后结果")
    private long disAllSumVIPEnd = 0;

    @Column(name = "dis_all_sum_vip", columnDefinition = "number(19) default 0")
    @Comment(value = "去重 VIP 总和")
    private long disAllSumVIP = 0;

    @Column(name = "all_sum_vip", columnDefinition = "number(19) default 0")
    @Comment(value = "VIP 总和")
    private long allSumVIP = 0;

    @Column(name = "score_total", columnDefinition = "number(19) default 0")
    @Comment(value = "总分")
    private int scoreTotal = 0;

    @Column(name = "safety_stock_qty", columnDefinition = "number(3) default 0")
    @Comment("安全库存")
    private double safetyStockQty = 0;

    @Column(name = "the_max_qty", columnDefinition = "number(3) default 0")
    @Comment("最高限量")
    private double theMaxQty = 0;

    @Column(name = "the_min_qty", columnDefinition = "number(3) default 0")
    @Comment("最低限量")
    private double theMinQty = 0;

    @Column(name = "stock_mark", nullable = false, columnDefinition = "number(1,0) default 0")
    @Comment("备货标记")
    private boolean stockMark;

    @Column(name = "SCORE_TOTAL_SERIAL_NUMBER", columnDefinition = "number(19) default 0")
    @Comment(value = "总分排序")
    private long scoreTotalSerialNumber = 0;

}
